﻿@using ToyStore.Domain.Store
@model Cart

@{
    ViewBag.Title = "Koszyk";
    Layout = "~/Views/Shared/_Layout.cshtml";
}



<h2>Koszyk</h2>

@if(Model != null && Model.CartItems.Count(c => c.IsDeleted == false) > 0)
{
	
	<div>
		Koszyk zawiera wybrane przez Ciebie audiobooki. Zakupione nagrania będą dostępne do pobrania on-line.
		Produkty będą zawsze dostępne na Twojej półce po zalogowaniu.
	</div>
	
	<h4>Produkty</h4>
	
	foreach (CartItem item in Model.CartItems.Where(c => c.IsDeleted == false))
	{
		@(Html.Partial("_ProductListTemplateInCart", item.Product))
	}

	<text>
		<div style="clear: both; font-size: 1.6em; padding-top: 20px;">Razem (brutto): <span id="sumInBasket"> @String.Format("{0:0.00} zł", Model.SumPriceBrutto)</span></div>
		<div style="float: right" id="goToCashBox">
			@(Html.ActionLink<CartController>(c => c.EmptyCart(), "Opróźnij koszyk"))
			@(Html.ActionLink<CartController>(c => c.CashBox(), "Przejdź do kasy", new { @class= "btn btn-small btn-primary" }))
		</div>
	</text>
}
else
{
	<div>Koszyk jest pusty</div>
}

<script type="text/javascript" language="javascript">
	$().ready(function () {
		$(".flipbox").find(".deleteFromCart a").on("click", function (event) { //remove from to chart
			event.preventDefault();
			var currentFlipbox = $(this).closest(".flipbox");
			var link = $(this);
			var productId = link.data("id");
			ShowAjaxLoader();
			$.ajax({
				type: 'POST',
				url: '@Url.Action("DeleteProductAjax", "Cart")',
				data: { id: productId },
				success: function (data) {
					if (data != undefined) {
						var result = $("#basketTemplate").tmpl(data);
						$("#basket").html(result);
						$("#sumInBasket").text(data.sum + " zł");
						HideAjaxLoader();
						currentFlipbox.fadeOut('slow');

						if (data.amount == 0) {
							$("#goToCashBox").hide();
						}
					}
				}
			});
		});
	});

</script>
<script id="basketTemplate" type="text/x-jquery-tmpl">
    <div id="basket-ico">
	</div>
	<div id="basket-info">
		w koszyku : ${amount} szt (${sum} zł)
		<br />
		@(Html.ActionLink<CartController>(c => c.Index(), "przejdź do koszyka"))
	</div>
</script>


 <script src="@Url.Content("/Scripts/jquery.flip.js")" type="text/javascript"></script>
 <script src="@Url.Content("/Scripts/productListTemplates.js")" type="text/javascript"></script>